<?php

namespace App\Http\Middleware;

use Closure;
use Api;
class ApiMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $data = $next($request)->getOriginalContent();

        if(Api::isDebug() === true)
        {
            return $data;
        }
        else
        {   
            $res = [
            'data' => $data,
            'state' => Api::getState(),
            'errors' => Api::getErrors(),
            ];
            return response()->json($res);
        }
    }
}
